<template>
  <div class="list">
    <ul class="tabs">
      <li v-for="item in state.tabsList" v-bind:key="item.item">
        <strong>{{ item.str }}</strong>
        <span
          @click="onactive(item.active)"
          v-bind:class="{ active: state.tabsList.active }"
          >{{ item.span }}</span
        >
      </li>
    </ul>
      <van-list
        v-model:loading="state.loading"
        :finished="state.finished"
        finished-text="没有更多了"
        @load="onLoad"
        class="item-relative"
      >
        <div
          class="item"
          v-for="item in state.itemList"
          v-bind:key="item.goods_id"
        >
          <div>
            <van-image
              width="164"
              height="164"
              :src=item.goods_img
              class="item-img"
            />
          </div>
          <div class="info-box">
            <div class="goods-name">
              {{item.title}}
            </div>
            <div class="currency-price">
              <span><i>￥</i>{{item.shop_price}}</span>
            </div>
          </div>
        </div>
      </van-list>
  </div>
</template>

<script>
import { reactive } from "vue";
import store from "../../../store/index.js";
export default {
  setup() {
    const state = reactive({
      tabsList: [
        { item: 1, str: "精选", span: "为你推荐", active: false },
        { item: 2, str: "社区", span: "新奇好物", active: false },
        { item: 3, str: "新品", span: "潮流上新", active: false },
        { item: 4, str: "热卖", span: "火热爆款", active: false },
      ],
      loading: false,
      finished: false,
      itemList: [],
      size: 10,
      page: 1,
    });

    const onactive = (item) => {
      item = true;
      console.log(state.tabsList.active);
    };

    const onLoad = () => {
      store
        .dispatch({
          type: "gethomegoods",
          size: state.size,
          page: state.page,
          type1: "is_best",
        })
        .then((data) => {
          state.itemList = [...state.itemList, ...data];
          state.page = state.page + 1;
          state.loading = true;
          state.finished = true;
        });
    };

    return {
      state,
      onactive,
      onLoad,
    };
  },
};
</script>


<style lang="less" scoped>
* {
  padding: 0;
  margin: 0;
}
.active {
  background: linear-gradient(-88deg, #ff4f2e, #f91f28);
  color: #fff !important;
}
.list {
  background-color: #f4f4f4;
  .tabs {
    display: flex;
    padding: 10px 0;
    justify-content: center;
    li {
      display: flex;
      flex-direction: column;
      align-items: center;
      strong {
        font-size: 16px;
        color: #333;
      }
      span {
        display: inline-block;
        font-size: 12px;
        border-radius: 10px;
        padding: 1px 8px;
        margin-top: 2px;
        color: #888;
      }
    }
  }
  .item-relative {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 0 5px;
    .item {
      width: 47%;
      // flex-wrap: wrap;
      border-radius: 16px;
      margin-bottom: 7px;
      background-color: #fff;
      padding: 5px;
      .item-img{
        overflow: hidden;
      }
      .goods-name {
        font-size: 15px;
        color: #000;
        font-weight: 500;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
      }
      .currency-price {
        margin-top: 8px;
        span {
          font-size: 18px;
          font-weight: 700;
          color: rgb(242, 14, 40);
          i {
            font-size: 12px;
            font-style: normal;
          }
        }
      }
    }
  }
}
</style>